#include "PhysicsTask.h"
#include "GlobalTimer.h"

bool PhysicsTask::Start()
{
	return true;
}

void PhysicsTask::Stop()
{
}

void PhysicsTask::Update()
{
	float dTime = GlobalTimer::getTime().getSecondsElapsed();
	float time = GlobalTimer::getTime().getSecondsSinceStart() - dTime;
	m_lastTime = GlobalTimer::getTime();

	if (dTime > 0.5)				// Clamp
		dTime = 0.5;
	for (System::Map_t::iterator it = m_systems.begin(), end = m_systems.end(); it != end; ++it)
	{
		it->second->Evaluate(dTime);
		// it->second->PrintObjects();
	}
}

void PhysicsTask::AddSystem( HashedString& name, System* system )
{
	m_systems.insert(System::Pair_t(name, system));
}

System* PhysicsTask::FindSystem( HashedString& name )
{
	System::Map_t::iterator it;
	if ((it = m_systems.find(name)) != m_systems.end()) 
		return it->second;
	return 0;
}

void PhysicsTask::RemoveSystem( HashedString& name )
{
	System::Map_t::iterator it;
	if ((it = m_systems.find(name)) != m_systems.end())
		m_systems.erase(it);
}
